<template>
  <div class="header">
    <div class="l-content">
        <!-- 左侧按钮 -->
        <el-button size="small" @click="handle">
            <!-- eslint-disable-next-line vue/require-component-is  临时禁用规则，这是会爆红，原因好像是没有遵循ESLint 规则-->
            <component class="icons" is="menu"></component>
        </el-button>
        <!-- 面包屑 -->
        <el-breadcrumb separator="/" class="bread">
            <el-breadcrumb-item :to="{ path: '/home' }" @click="goToback">首页</el-breadcrumb-item>
            <el-breadcrumb-item v-show="currentMenu!=='首页'&&currentMenu">{{currentMenu}}</el-breadcrumb-item>
        </el-breadcrumb>
        <FilePopup/>
    </div>
 
    <!-- 右侧头像 -->
    <div class="r-content">
        <el-dropdown>
            <span class="el-dropdown-link">
                <el-avatar >
                  <img :src="userStor.state.userInfo.avatar" class="user" />
                </el-avatar>
            </span>
            <template #dropdown>
                <el-dropdown-menu>
                    <el-dropdown-item @click="toUser">个人中心</el-dropdown-item>
                    <el-dropdown-item @click="goback">退出</el-dropdown-item>
                </el-dropdown-menu>
            </template>
        </el-dropdown>        
    </div>
    
  </div>
</template>

<script setup>
import {ref, computed,onMounted} from 'vue'
import {useAllDataStore} from '@/stores'
import { useRouter } from 'vue-router';//引入路由
import FilePopup from '@/components/disk/FilePopup.vue';
import {userStore} from '@/stores/disk/user'
import {logout} from '@/api/login/LoginForm'
const userStor = userStore()
const router = useRouter();
const store =useAllDataStore()



const handle=()=>{
  store.state.isCollapse = !store.state.isCollapse
}

const goback=()=>{
  // 这里可以用router.push() 跳转到登录页面
  logout()
  //清除本地存储
  localStorage.removeItem('token');
  localStorage.removeItem('userId');
  router.replace('/login')
}

const currentMenu = computed(() => {
  return store.state.currentMenu
})

const goToback=()=>{
  store.updateCurrentMenu(null)
}

const toUser=()=>{
  const data={
    path: 'user',
    name: 'user',
    icon: 'location',
    label: '个人中心',
  }
  store.selectMenu(data)
  store.updateCurrentMenu(data.label)
  router.push('/user')
}

onMounted(() => {
  userStor.getUser()
})
</script>

<style scoped lang="less">
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  background-color: #ffffff;
}
.icons {
  width: 20px;
  height: 20px;
}
.l-content {
  display: flex;
  align-items: center;
  .el-button {
      margin-right: 20px;
   }
}
.r-content {
  .user{
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}

:deep(.bread span){
    color: #000000 !important;
    cursor:pointer !important;
}  

</style>

